home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
embedded
/
ibm
/
ashc5.arc
/
FFWD.C
< prev
next >
Wrap
Text File
|
1990-07-15
|
2KB
|
97 lines
/*
* file I/O version of forward ref handler
*/
#define FILEMODE 0644 /* file creat mode */
#define UPDATE 2 /* file open mode */
#define ABS 0 /* absolute seek */
int Forward =0; /* temp file's file descriptor */
char Fwd_name[] = { "Fwd_refs" } ;
/*
* fwdinit --- initialize forward ref file
*/
fwdinit()
{
Forward = creat(Fwd_name,FILEMODE);
if(Forward <0)
fatal("Can't create temp file");
close(Forward); /* close and reopen for reads and writes */
Forward = open(Fwd_name,UPDATE);
if(Forward <0)
fatal("Forward ref file has gone.");
}
/*
* fwdreinit --- reinitialize forward ref file
*/
fwdreinit()
{
int stat;
long lstat;
F_ref = 0;
Ffn = 0;
lstat = lseek(Forward,0L,ABS); /* rewind forward refs */
if( lstat == (long)ERR ) fatal("Unable to read forward ref file");
stat = read(Forward,&Ffn,sizeof(Ffn));
if( stat == ERR ) fatal("Unable to read forward ref file");
stat = read(Forward,&F_ref,sizeof(F_ref)); /* read first forward ref into mem */
if( stat == ERR ) fatal ("Unable to read forward ref file");
#ifdef DEBUG
printf("First fwd ref: %d,%d\n",Ffn,F_ref);
#endif
}
/*
* fwdmark --- mark current file/line as containing a forward ref
*/
fwdmark()
{
int stat;
stat = write(Forward,&Cfn,sizeof(Cfn));
if( stat == ERR ) fatal("Unable to write to forward ref file");
stat = write(Forward,&Line_num,sizeof(Line_num));
if( stat == ERR ) fatal("Unable to write to forward ref file");
}
/*
* fwdnext --- get next forward ref
*/
fwdnext()
{
int stat;
stat = read(Forward,&Ffn,sizeof(Ffn));
if( stat == ERR ) fatal("Unable to read forward ref file");
#ifdef DEBUG
printf("Ffn stat=%d ",stat);
#endif
stat = read(Forward,&F_ref,sizeof(F_ref));
if( stat < sizeof(F_ref) ){
if( stat == ERR ) fatal("Unable to read forward ref file");
F_ref=0;
Ffn=0;
}
#ifdef DEBUG
printf("F_ref stat=%d ",stat);
printf("Next Fwd ref: %d,%d\n",Ffn,F_ref);
#endif
}
/*
* fwd_done --- closes & deletes forward reference file
*/
fwd_done()
{
int stat;
stat = close(Forward); /* Have to close first on MS-DOS or you leave lost clusters. */
#ifndef DEBUG
if( stat == 0 ) /* If close was successful, delete file */
unlink(Fwd_name);
#endif
}